﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.BLL;

public partial class Controls_Tour_ctrTourCatDetail : System.Web.UI.UserControl
{
    private int nCurrentlanguage = Support.GetCurrentLanguage();
    private int nDefaultLanguage = Support.GetDefaultLanguage();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.Initdata();
        }
    }
    private void Initdata()
    {
        lblTopDeal.Text = MultipleLanguage.TOPDEAL[nCurrentlanguage - 1];
        lnkShowall.Text = MultipleLanguage.GETMORETOUR[nCurrentlanguage - 1];
        int nCountry = this.GetCountry();
        TourCategory objTourCat = new TourCategory();
        DataTable dtbCat = new DataTable();

        int nTourCat = ConvertData.ConvertToInt(Request.QueryString[Config.TOUR_CAT]);

        dtbCat = objTourCat.Search(-1, this.GetCountry());

        if (nTourCat <= 0)
        {   
        nTourCat = ConvertData.ConvertToInt(dtbCat.Rows[0]["TourCategoryID"]);
        }
        objTourCat.LoadById(nTourCat);
        switch (nCurrentlanguage)
        {
            case 1:
                //lblTourCatName.Text = objTourCat.Data.TourCategoryName1;
                ltrTourCat.Text = objTourCat.Data.TourCategoryDetail1;
                break;
            case 2:
                ltrTourCat.Text = objTourCat.Data.TourCategoryDetail2;
             //   lblTourCatName.Text = objTourCat.Data.TourCategoryName2;
                break;
            case 3:
                ltrTourCat.Text = objTourCat.Data.TourCategoryDetail3;
             //   lblTourCatName.Text = objTourCat.Data.TourCategoryName3;
                break;
        }
        imgTourCat.ImageUrl = Config.ROOT + Config.IMAGE_TOURCAT_DEFAULT_UPLOAD + objTourCat.Data.Images;
        this.TopDeal(nTourCat);
        lnkShowall.NavigateUrl = "~/TourCategory.aspx?" + Config.TOUR_CAT + "=" + nTourCat + "&cid=" + GetCountry();
    }

    private int GetCountry()
    {
        int nCountry = 0;
        nCountry = ConvertData.ConvertToInt(Request.QueryString[Config.COUNTRY]);
        if (nCountry == 0)
            nCountry = Config.COUNTRY_DEFAULT;
        return nCountry;
    }

    private void TopDeal(int nTourCat)
    {
        Tours objTours = new Tours();
        DataTable dtbTour = new DataTable();
        int nPageCount = 0;
        dtbTour = objTours.Search(4, 0, "", 0, 0, 0, 0, 0, 0, ConvertData.ConvertToString(nTourCat), nDefaultLanguage, nCurrentlanguage, -1, 1, 1, 5, ref nPageCount);
        //if (dtbTour.Rows.Count == 4)
        //{
        //    lnkReadAll.Visible = true;
        //    lnkReadAll.Text = MultipleLanguage.LINK_READMORE[nCurrentlanguage - 1];
        //    lnkReadAll.NavigateUrl = Config.ROOT + Pages.FrontEnds.TOUR_LIST + "?" + Config.TOUR_CAT + "="
        //        + ConvertData.ConvertToString(nTourCat)
        //        + "&" + Config.SEARCH_TYPE + "=1";
        //}
        //else
        //{
        //    lnkReadAll.Visible = false;
        //}
        rptTour.DataSource = dtbTour;
        rptTour.DataBind();
    }
 
    protected void rptTour_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        string strCommand = e.CommandName;
        int nID = ConvertData.ConvertToInt(e.CommandArgument);

        switch (strCommand)
        {
            case "image":
                string sDetail = Config.ROOT + Pages.FrontEnds.TOUR_DETAIL + "?" + Config.TOUR_ID + "=" + nID + "&cid=" + this.GetCountry();
                Response.Redirect(sDetail);
                break;
        }
    }
  
    protected void rptTour_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            int nCurrentLanguage = Support.GetCurrentLanguage();
            int nDefaultLanguage = Support.GetDefaultLanguage();

            HyperLink lnkTourName = (HyperLink)e.Item.FindControl("lnkTourName");
            Literal ltrTour = (Literal)e.Item.FindControl("ltrTour");
            Label lblDuration = (Label)e.Item.FindControl("lblDuration");
            ImageButton imgbtnTour = (ImageButton)e.Item.FindControl("imgTour");
            HyperLink lnkReadAll = (HyperLink)e.Item.FindControl("lnkReadAll");

            lnkReadAll.Text = MultipleLanguage.LNK_READMORE[nCurrentlanguage - 1];
            lnkTourName.NavigateUrl = Config.ROOT + Pages.FrontEnds.TOUR_DETAIL + "?" + Config.TOUR_ID + "=" + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TourID")) + "&cid=" + this.GetCountry(); 
            lnkReadAll.NavigateUrl = Config.ROOT + Pages.FrontEnds.TOUR_DETAIL + "?" + Config.TOUR_ID + "=" + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TourID")) + "&cid=" + this.GetCountry(); 
          
            imgbtnTour.ImageUrl = Config.ROOT + Config.IMAGE_TOUR_UPLOAD + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Image"));
            imgbtnTour.CommandArgument = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "TourID"));
            lblDuration.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "DurationDescription2"));
          
          string sInit = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "InitContent"));
          if (sInit.Length > 190)
              sInit = ConvertData.TruncateString(sInit, 190) + "...";
          ltrTour.Text = sInit;
            lnkTourName.Text = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "Title"));
        }
    }
}